package com.masterclient.app.modules.search;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eoner.baselib.utils.sp.SPUtils;
import com.eoner.baselibrary.bean.firstpager.SearchConditionBean;
import com.eoner.baselibrary.utils.CloneUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.modules.search.adapter.BrandGridAdapter;
import com.masterclient.app.modules.search.adapter.CateGridAdapter;
import com.masterclient.app.modules.search.adapter.OtherGridAdapter;
import com.masterclient.app.modules.search.adapter.PromotionAdapter;
import com.masterclient.app.modules.search.adapter.SearchAssociateAdapter;
import com.masterclient.app.modules.search.beans.SearchAssociateBean;
import com.masterclient.app.modules.search.contract.SearchAssociateContract;
import com.masterclient.app.modules.search.contract.SearchAssociatePresenter;
import com.masterclient.app.utils.CommonUtil;
import com.masterclient.app.widget.NonScrollGridView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnEditorAction;
import io.reactivex.disposables.Disposable;

import static com.eoner.common.config.Config.SEARCH_HISTORY;

/**
 * 作者：sean
 * 创建时间：2017/6/23 09:45
 * 功能说明：
 */

public class SearchResultActivity extends BaseActivity<SearchAssociatePresenter> implements SearchAssociateContract.View {

    @BindView(R.id.frame_layout)
    FrameLayout frameLayout;
    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.et_min_price)
    EditText etMinPrice;
    @BindView(R.id.et_max_price)
    EditText etMaxPrice;
    @BindView(R.id.iv_brand_nine)
    ImageView ivBrandNine;
    @BindView(R.id.noScrollBrand)
    NonScrollGridView noScrollBrand;
    @BindView(R.id.ll_condition_brand)
    LinearLayout llConditionBrand;
    @BindView(R.id.rl_brand_nine)
    RelativeLayout rlBrandNine;
    @BindView(R.id.rl_cate_nine)
    RelativeLayout rlCateNine;
    @BindView(R.id.iv_cate_nine)
    ImageView ivCateNine;
    @BindView(R.id.noScrollCate)
    NonScrollGridView noScrollCate;
    @BindView(R.id.ll_condition_category)
    LinearLayout llConditionCategory;
    @BindView(R.id.ll_condition_other)
    LinearLayout llConditionOther;
    @BindView(R.id.tv_reset)
    TextView tvReset;
    @BindView(R.id.tv_complete)
    TextView tvComplete;
    @BindView(R.id.ll_bottom)
    LinearLayout llBottom;
    @BindView(R.id.left_drawer)
    RelativeLayout leftDrawer;
    @BindView(R.id.drawerLayout)
    DrawerLayout drawerLayout;
    @BindView(R.id.et_search_text)
    EditText etSearchText;
    @BindView(R.id.search_result_clear)
    FrameLayout searchClear;
    @BindView(R.id.rl_title_activity)
    RelativeLayout rlTitleActivity;
    @BindView(R.id.ll_activity)
    LinearLayout llActivity;
    @BindView(R.id.noScrollPromotion)
    NonScrollGridView noScrollPromotion;
    @BindView(R.id.recycler_search_associate)
    RecyclerView recyclerSearchAssociate;
    private SearchAssociateAdapter associateAdapter;
    private boolean isAssociate = false;
    public Disposable disposable;

    private SearchGoodResultFragment searchGoodResultFragment;
    private SearchShopResultFragment searchShopResultFragment;
    String keyword;
    private String attributes,brandIds,cids,end_price,start_price;

    //克隆对象
    List<SearchGoodBean.DataBean.ShBrandsBean> cloneBrandBeans;
    List<SearchGoodBean.DataBean.ShCategorysBean> cloneCateBeans;
    List<SearchGoodBean.DataBean.ShAttributesBean> cloneAttrBeans;
    List<SearchGoodBean.DataBean.ShPromotionsBean> clonePromotions;

    private BrandGridAdapter brandGridAdapter;
    private CateGridAdapter cateGridAdapter;
    private PromotionAdapter promotionAdapter;

    private SearchConditionBean conditionBean;

    Gson gson = new Gson();
    private List<String> historyQueue;
    private String history;
    public String search_type;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_result);
        ButterKnife.bind(this);

        history = SPUtils.getInstance().getString(SEARCH_HISTORY);
        search_type = getIntent().getStringExtra("search_type");
        historyQueue = gson.fromJson(history,new TypeToken<ArrayList<String>>() {
        }.getType());
        keyword = getBundleString("keyword");
        isAssociate = true;
        etSearchText.setText(keyword);
        searchGoodResultFragment = SearchGoodResultFragment.getInstance(keyword);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_layout, searchGoodResultFragment, "SearchGoodResultFragment")
                .commit();

        conditionBean = new SearchConditionBean();

        leftDrawer.getLayoutParams().width = (int) (ScreenUtils.getScreenWidth() * 0.77);
        searchGoodResultFragment.setOnOpenDrawerListerner(new SearchGoodResultFragment.OnOpenDrawerListerner() {
            @Override
            public void onOpenListerner(SearchGoodBean.DataBean dataBean) {
                drawerLayout.setFadingEdgeLength((int) (ScreenUtils.getScreenWidth() * 0.88));
                drawerLayout.openDrawer(Gravity.RIGHT);
//                dataBean.getSh_attributes();
            }

            @Override
            public void onRefreshCondition(SearchGoodBean.DataBean dataBean,boolean isFirst) {
                if(isFirst){
                    isFirst = false;
                }else {
                    return;
                }
                //品牌
                if (dataBean.getSh_brands() != null) {
                    cloneBrandBeans = (List<SearchGoodBean.DataBean.ShBrandsBean>) CloneUtil.deepClone(dataBean.getSh_brands());
                }
                initBrands(dataBean);

                //类别
                if (dataBean.getSh_categorys() != null) {
                    cloneCateBeans = (List<SearchGoodBean.DataBean.ShCategorysBean>) CloneUtil.deepClone(dataBean.getSh_categorys());
                }
                initCate(dataBean);

                //其它
                if (dataBean.getSh_categorys() != null) {
                    cloneAttrBeans = (List<SearchGoodBean.DataBean.ShAttributesBean>) CloneUtil.deepClone(dataBean.getSh_attributes());
                }

                initAttributes();

                if(dataBean.getSh_promotions() != null){
                    clonePromotions = (List<SearchGoodBean.DataBean.ShPromotionsBean>) CloneUtil.deepClone(dataBean.getSh_promotions());
                }else {
                    llActivity.setVisibility(View.GONE);
                }
                initPromotions();
            }
        });

        recyclerSearchAssociate.setLayoutManager(new LinearLayoutManager(this));
        associateAdapter = new SearchAssociateAdapter();
        recyclerSearchAssociate.setAdapter(associateAdapter);

        associateAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String target = associateAdapter.getData().get(position).getTarget_type();
                String target_id = associateAdapter.getData().get(position).getTarget_value();
                String keyword = associateAdapter.getData().get(position).getKey_word();
                isAssociate = false;
                if (TextUtils.isEmpty(target)) {
                    etSearchText.setText(keyword);
                    etSearchText.setSelection(keyword.length());
                    SearchResultActivity.this.keyword = keyword;
                    search_type = "推荐词";
                    searchKeywords(keyword);
                }else {
                    CommonUtil.goAnyWhere(SearchResultActivity.this,target,target_id,"","","");
                }
            }
        });

        etSearchText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                searchClear.setVisibility(charSequence.toString().length()>0?View.VISIBLE:View.INVISIBLE);
                if (isAssociate&&etSearchText.getText().toString().length()>0){
                    if (disposable != null && !disposable.isDisposed()) disposable.dispose();
                    disposable = mPresenter.searchAssociate(etSearchText.getText().toString());
                }else {
                    recyclerSearchAssociate.setVisibility(View.GONE);
                }
                isAssociate = true;
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        etMinPrice.setOnFocusChangeListener((v,hasFocus)-> {
            if(!hasFocus){
                hideSoftInput(etMinPrice);
            }
        });

        etMaxPrice.setOnFocusChangeListener((v,hasFocus)-> {
            if(!hasFocus){
                hideSoftInput(etMaxPrice);
            }
        });

//        rxBus = RxBus.$();
//        rxBus.OnEvent(rxBus.register(Config.MSG_UNREAD), new Consumer<Object>() {
//            @Override
//            public void accept(@NonNull Object o) throws Exception {
//                if(Config.UNREAD>0){
//                    ivUnread.setVisibility(View.VISIBLE);
//                }else {
//                    ivUnread.setVisibility(View.INVISIBLE);
//                }
//            }
//        });
    }

    @Override
    protected void onResume() {
        MobclickAgent.onEvent(mContext, "page_search");
        super.onResume();
    }

    @Override
    protected void onPause() {
        hideSoftInput(etSearchText);
        super.onPause();
    }


    private void initPromotions() {
        if(clonePromotions != null&&clonePromotions.size()>0){
            promotionAdapter = new PromotionAdapter(mContext);
            noScrollPromotion.setAdapter(promotionAdapter);
            promotionAdapter.setList(clonePromotions,"");

            noScrollPromotion.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    conditionBean.setPromotion_type(clonePromotions.get(position).getSh_id());
                    promotionAdapter.setList(clonePromotions,conditionBean.getPromotion_type());
                }
            });

        }else {
            llActivity.setVisibility(View.GONE);
        }
    }


    @OnEditorAction(R.id.et_search_text) boolean onEditSearch(TextView tv, int imeAction, KeyEvent event){
        if (imeAction == EditorInfo.IME_ACTION_SEARCH) {
            // 当按了搜索之后关闭软键盘
            String search = tv.getText().toString().trim();
            ((InputMethodManager) tv.getContext().getSystemService(
                    Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                    getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            if(TextUtils.isEmpty(search)){
                showToast("搜索内容不能为空");
//                historyQueue.offer(search)
            }else {
                    keyword = search;
                    search_type = "自搜词";
                searchKeywords(keyword);
            }
            return true;
        }
        return false;
    }

    private boolean brandOpen = false;
    private void initBrands(SearchGoodBean.DataBean dataBean) {
//        if(cloneBrandBeans != null&&cloneBrandBeans.size()>0){
//            if (dataBean.getSh_brands().size() > 3) {
//                ivBrandNine.setVisibility(View.VISIBLE);
//            }else {
//                ivBrandNine.setVisibility(View.GONE);
//            }
//            rlBrandNine.setOnClickListener(v->{
//                if(brandOpen){
//                    ivBrandNine.setImageResource(R.mipmap.down_icon);
//                    brandOpen = false;
//                    brandGridAdapter.setList(cloneBrandBeans,false);
//                }else {
//                    ivBrandNine.setImageResource(R.mipmap.shouqi_icon);
//                    brandOpen = true;
//                    brandGridAdapter.setList(cloneBrandBeans,true);
//                }
//            });
//            llConditionBrand.setVisibility(View.VISIBLE);
//            brandGridAdapter = new BrandGridAdapter(mContext);
//            noScrollBrand.setAdapter(brandGridAdapter);
//            brandGridAdapter.setList(cloneBrandBeans,cloneBrandBeans.size()>=3?false:true);
//            noScrollBrand.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//                @Override
//                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                    SearchGoodBean.DataBean.ShBrandsBean brandsBean = cloneBrandBeans.get(position);
////                    mRequestFocus(view);
////                    hideSoftInput(etMaxPrice);
//                    if(brandsBean.isCheck()){
//                        brandsBean.setCheck(false);
//                    }else {
//                        brandsBean.setCheck(true);
//                    }
//                    brandGridAdapter.notifyDataSetChanged();
//                }
//            });
//        } else {
//            llConditionBrand.setVisibility(View.GONE);
//        }
    }

    private void searchKeywords(String search){
        recyclerSearchAssociate.setVisibility(View.GONE);
        if(searchGoodResultFragment!=null){
            if(searchGoodResultFragment.isVisible()){
                searchGoodResultFragment.searchNewKeyWord(search);
            }else {
                searchGoodResultFragment.setNewKeyWord(search);
            }
        }

        if(searchShopResultFragment!=null){
            if(searchShopResultFragment.isVisible()){
                searchShopResultFragment.searchNewKeyWord(keyword);
            }else {
                searchShopResultFragment.setNewKeyWord(keyword);
            }
        }

        if(historyQueue == null){
            historyQueue = new ArrayList<>();
            historyQueue.add(search);
            SPUtils.getInstance().put(SEARCH_HISTORY,gson.toJson(historyQueue));
        }else {
            if(historyQueue.contains(search)){
                historyQueue.remove(search);
                historyQueue.add(search);
                SPUtils.getInstance().put(SEARCH_HISTORY,gson.toJson(historyQueue));
            }else {
                historyQueue.add(search);
                SPUtils.getInstance().put(SEARCH_HISTORY,gson.toJson(historyQueue));
            }
        }
    }
//    @Override
//    public void finish() {
//        Intent intent = new Intent();
//        setResult(103,intent.putExtra("keyword",etSearchText.getText().toString().trim()));
//        super.finish();
//    }

//    private void mRequestFocus(View view) {
//        view.setFocusable(true);
//        view.setFocusableInTouchMode(true);
//        view.requestFocus();
//    }

    private boolean cateOpen = false;
    private void initCate(SearchGoodBean.DataBean dataBean) {
        if(cloneCateBeans!=null&&cloneCateBeans.size()>0){

            rlCateNine.setOnClickListener(v->{
                if(cateOpen){
                    ivCateNine.setImageResource(R.mipmap.search_down);
                    cateOpen = false;
                    cateGridAdapter.isShow(false);
                }else {
                    ivCateNine.setImageResource(R.mipmap.search_up);
                    cateOpen = true;
                    cateGridAdapter.isShow(true);
                }
            });

            llConditionCategory.setVisibility(View.VISIBLE);
            cateGridAdapter = new CateGridAdapter(mContext);
            noScrollCate.setAdapter(cateGridAdapter);
            cateGridAdapter.setList(cloneCateBeans);

            if(dataBean.getSh_categorys().size()>3){
                ivCateNine.setVisibility(View.VISIBLE);
                cateGridAdapter.isShow(false);
            }else {
                ivCateNine.setVisibility(View.GONE);
            }

            noScrollCate.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SearchGoodBean.DataBean.ShCategorysBean categorysBean = cloneCateBeans.get(position);
//                    mRequestFocus(view);
                    if(categorysBean.isCheck()){
                        categorysBean.setCheck(false);
                    }else {
                        categorysBean.setCheck(true);
                    }
                    cateGridAdapter.notifyDataSetChanged();
                }
            });
        } else {
            llConditionCategory.setVisibility(View.GONE);
        }
    }

    private void initAttributes() {
        llConditionOther.removeAllViews();
        if (cloneAttrBeans != null) {
            for (SearchGoodBean.DataBean.ShAttributesBean bean : cloneAttrBeans) {
                LinearLayout linearLayout = (LinearLayout) View.inflate(mContext, R.layout.view_search_condition_selector, null);
                TextView tv_attr_name = (TextView) linearLayout.findViewById(R.id.tv_attr_name);
                ImageView iv_arrow = (ImageView) linearLayout.findViewById(R.id.iv_arrow);
                RelativeLayout rl_arrow = (RelativeLayout) linearLayout.findViewById(R.id.rl_arrow);

                tv_attr_name.setText(bean.getSh_attribute_name());
                if (bean.getSh_options() != null && bean.getSh_options().size() > 3) {
                    iv_arrow.setVisibility(View.VISIBLE);
                } else {
                    iv_arrow.setVisibility(View.GONE);
                }
                NonScrollGridView gridView = (NonScrollGridView) linearLayout.findViewById(R.id.noScrollGrid);
                OtherGridAdapter gridAdapter = new OtherGridAdapter(mContext);
                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        SearchGoodBean.DataBean.ShAttributesBean.ShOptionsBean shOptionsBean = bean.getSh_options().get(position);
//                        mRequestFocus(view);
                        if(shOptionsBean.isCheck()){
                            shOptionsBean.setCheck(false);
                        }else {
                            shOptionsBean.setCheck(true);
                        }
                        gridAdapter.notifyDataSetChanged();
                    }
                });


                rl_arrow.setOnClickListener(v->{
                    if(bean.attrOpen){
                        iv_arrow.setImageResource(R.mipmap.search_down);
                        bean.attrOpen = false;
                        gridAdapter.isShow(false);
                    }else {
                        iv_arrow.setImageResource(R.mipmap.search_up);
                        bean.attrOpen = true;
                        gridAdapter.isShow(true);
                    }
                });
                gridView.setAdapter(gridAdapter);
                gridAdapter.setList(bean.getSh_options());

                if (bean.getSh_options() != null && bean.getSh_options().size() > 3) {
                    iv_arrow.setVisibility(View.VISIBLE);
                    gridAdapter.isShow(false);
                } else {
                    iv_arrow.setVisibility(View.GONE);
                }

                llConditionOther.addView(linearLayout);
            }
        } else {
            llConditionOther.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.iv_back,R.id.view_back, R.id.search_result_clear/*, R.id.rl_message, R.id.rl_et*/,R.id.tv_reset,R.id.tv_complete})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.search_result_clear:
                etSearchText.setText("");
                break;
//            case R.id.rl_message:
//                CustomerService.getInstance(mContext).connectService("搜索结果",null, Config.CUSTOMER);
//                break;
//            case R.id.tv_goods:
//                tvGoods.setTextColor(0xffF23051);
////                tvShop.setTextColor(0xff141922);
//                tvGoods.setBackgroundResource(R.drawable.shape_round_ffe4e9);
////                tvShop.setBackground(null);
//                searchGoodResultFragment.setNewKeyWord(keyword);
//                getSupportFragmentManager()
//                        .beginTransaction()
//                        .replace(R.id.frame_layout, searchGoodResultFragment, "SearchGoodResultFragment")
//                        .commit();
//                break;
//            case R.id.tv_shop:
//                tvGoods.setTextColor(0xff141922);
//                tvShop.setTextColor(0xffF23051);
//                tvGoods.setBackground(null);
//                tvShop.setBackgroundResource(R.drawable.shape_round_ffe4e9);
//                if (searchShopResultFragment == null) {
//                    searchShopResultFragment = SearchShopResultFragment.getInstance(keyword);
//                }else{
//                    searchShopResultFragment.setNewKeyWord(keyword);
//                }
//                getSupportFragmentManager()
//                        .beginTransaction()
//                        .replace(R.id.frame_layout, searchShopResultFragment, "SearchShopResultFragment")
//                        .commit();
//                break;
            case R.id.iv_back:
                // 当按了搜索之后关闭软键盘
                String search = etSearchText.getText().toString().trim();
                hideSoftInput(etSearchText);
                if(TextUtils.isEmpty(search)){
                    showToast("搜索内容不能为空");
//                historyQueue.offer(search)
                }else {
                    keyword = search;
                    search_type = "自搜词";
                    searchKeywords(keyword);
                }
                break;
            case R.id.view_back:
                finish();
                break;
//            case R.id.rl_et:
//                finish();
//                break;
            case R.id.tv_reset:
                if(cloneBrandBeans!=null){
                    for(SearchGoodBean.DataBean.ShBrandsBean brandsBean:cloneBrandBeans){
                        brandsBean.setCheck(false);
                    }
                }
                if(cloneCateBeans!=null){
                    for(SearchGoodBean.DataBean.ShCategorysBean categorysBean:cloneCateBeans){
                        categorysBean.setCheck(false);
                    }
                }

                if(cloneAttrBeans!=null){
                    for(SearchGoodBean.DataBean.ShAttributesBean shAttributesBean:cloneAttrBeans){
                        if(shAttributesBean.getSh_options()!=null){
                            for(SearchGoodBean.DataBean.ShAttributesBean.ShOptionsBean shOptionsBean:shAttributesBean.getSh_options()){
                                shOptionsBean.setCheck(false);
                            }
                        }
                    }
                }

                if(brandGridAdapter!=null){
                    brandGridAdapter.notifyDataSetChanged();
                }
                if(cateGridAdapter!=null){
                    cateGridAdapter.notifyDataSetChanged();
                }
                initAttributes();
                etMinPrice.setText("");
                etMaxPrice.setText("");

                //初始化特惠和秒杀
                conditionBean.setPromotion_type("");
                if(promotionAdapter!=null){
                    promotionAdapter.setList(clonePromotions,conditionBean.getPromotion_type());
                }
                break;
            case R.id.tv_complete:
                String minPrice = etMinPrice.getText().toString().trim();
                String maxPrice = etMaxPrice.getText().toString().trim();

                conditionBean.setStart_price(minPrice);
                conditionBean.setEnd_price(maxPrice);

                conditionBean.setBrand_ids(null);
                if(cloneBrandBeans!=null){
                    for(SearchGoodBean.DataBean.ShBrandsBean brandsBean:cloneBrandBeans){
                        if(brandsBean.isCheck()){
                            List<String> brandIds = new ArrayList<>();
                            brandIds.add(brandsBean.getSh_id());
                            conditionBean.setBrand_ids(brandIds);
                        }
                    }
                }

                conditionBean.setCids(null);
                if(cloneCateBeans!=null){
                    for(SearchGoodBean.DataBean.ShCategorysBean categorysBean:cloneCateBeans){
                        if(categorysBean.isCheck()){
                            List<String> cids = new ArrayList<>();
                            cids.add(categorysBean.getSh_cid());
                            conditionBean.setCids(cids);
                        }
                    }
                }

                conditionBean.setAttributes(null);
                if(cloneAttrBeans!=null){
                    Map<String,String> map = new HashMap<>();
                    for(SearchGoodBean.DataBean.ShAttributesBean shAttributesBean:cloneAttrBeans){
                        if(shAttributesBean.getSh_options()!=null){
                            for(SearchGoodBean.DataBean.ShAttributesBean.ShOptionsBean shOptionsBean:shAttributesBean.getSh_options()){
                                if(shOptionsBean.isCheck()){
                                    if(map.containsKey(shAttributesBean.getSh_attribute_id())){
                                        String str = map.get(shAttributesBean.getSh_attribute_id());
                                        map.put(shAttributesBean.getSh_attribute_id(),str+","+shOptionsBean.getSh_value());
                                    }else {
                                        map.put(shAttributesBean.getSh_attribute_id(),shOptionsBean.getSh_value());
                                    }
                                }
                            }
                        }
                    }
                    conditionBean.setAttributes(map);
                }

                searchGoodResultFragment.searchGoods(conditionBean);
                drawerLayout.closeDrawers();

                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        rxBus.unregister(Config.MSG_UNREAD);
    }


    @Override
    public void loadFailed(String msg) {

    }

    @Override
    public void showSearchAssociate(String keyword, List<SearchAssociateBean> beans) {
        if (etSearchText.getText().toString().length()>0&&beans!=null&&beans.size()>0) {
            if (etSearchText.getText().toString().equals(keyword)) {
                associateAdapter.setNewData(beans);
            }
            recyclerSearchAssociate.setVisibility(View.VISIBLE);
        }else {
            recyclerSearchAssociate.setVisibility(View.GONE);
        }
    }
}
